;var module = angular.module('CtrlsContent');
module.controller('BLSCtrl',['$scope','$ionicPopup','api_other',function($scope,$ionicPopup,api_other){
	$scope.model = {
		banner:'images/img/bg_index_banner.jpg',
		link:'',
		testTime:'',
		showTime:0
	};
	$scope.event = {
		/*loginPop:function(){
			if(!$scope.eleStatus.isLogin){
				$ionicPopup.show({
				    templateUrl: 'login.html',
				    scope: $scope,
				})
			};

		},*/
		getBanner:function(){
			var obj = {
				cat_id:localStorage.catId,
				type:1
			};
			var promise = api_other.getBanner(obj);
			promise.success(function(data){
				if(data.returnCode == 0){
					$scope.model.banner = "http://"+data.returnData.cover;
					$scope.model.link = "http://"+data.returnData.link;
				}
			})
		},
		closePop:function(){
			angular.forEach($scope.eleStatus, function(data,index,array){
				array[index] = false;
			});
		},
		setTime:function(){
			var setTime = (new Date($scope.model.testTime)).getTime();
			var currTiem = new Date().getTime();
			if((setTime-currTiem)/(24*3600*1000)<0){
				$scope.model.testTime = '';
				return ;
			}
			var obj = {
				userId:localStorage.bls_userId,
				time:$filter('date')($scope.model.testTime,'yyyy-MM-dd')
			}
			var promise = api_other.setTime(obj);
			promise.success(function(data){
				if(data.returnCode == 0){
					$scope.model.showTime = Math.floor((setTime-currTiem)/(24*3600*1000));
				}else{
					alert('设置失败')
				}
			})
		},
		getTime:function(){
			var obj = {
				userId:localStorage.bls_userId
			};
			var promise = api_other.getTime(obj);
			promise.success(function(data){
				if(data.returnCode == 0){
					$scope.model.testTime = new Date(data.returnData.days);
					var setTime = (new Date($scope.model.testTime)).getTime();
					var currTiem = new Date().getTime();
					if((setTime-currTiem)/(24*3600*1000)<0){
						$scope.model.testTime = '';
						return ;
					}
					$scope.model.showTime = Math.floor((setTime-currTiem)/(24*3600*1000));
				}else{
					alert('设置失败');
				}
			})
		}
		
	};
	$scope.eleStatus = {
		mask:false,
		isTestSelectShow:false,
	};
	$scope.blsPop = {
		login:''
	};
	(function(){
		$scope.event.getBanner();
		$scope.event.getTime();
	})();
}]);